﻿using System;
using System.Text;

class Calculator
{
    static void Main()
    {
        ShowMenu();
        int option = ReadNumber("Please enter an option: ");
        ValidateOption(option);

        int firstNumber = ReadNumber("Enter first number: ");
        int secondNumber = ReadNumber("Enter second number: ");   

        switch (option)
        {   
            case 1:
                Console.WriteLine("Result: {0}", AddNumbers(firstNumber, secondNumber));
                break;
            case 2:
                Console.WriteLine("Result: {0}", SubstractNumbers(firstNumber, secondNumber));
                break;
            case 3:
                Console.WriteLine("Result: {0}", MultiplyNumbers(firstNumber, secondNumber));
                break;
        }
    }
    private static void ShowMenu()
    {
        StringBuilder output = new StringBuilder();
        output.Append(new string(' ', 10));
        output.Append(new string('*', 24)).Append("\n");
        output.Append(new string(' ', 10));
        output.Append("*").Append(new string(' ', 22)).Append("*\n");
        output.Append(new string(' ', 10));
        output.Append("* Welcome to Math App! *\n");
        output.Append(new string(' ', 10));
        output.Append("*").Append(new string(' ', 22)).Append("*\n");
        output.Append(new string(' ', 10));
        output.Append(new string('*', 24)).Append("\n\n");

        output.Append("Please choose one of the options from the menu above:\n");
        output.Append("1). Add numbers\n");
        output.Append("2). Substact numbers\n");
        output.Append("3). Multiply numbers\n");

        Console.WriteLine(output.ToString());
    }
    static int ReadNumber(string msg)
    {
        try
        {
            Console.Write(msg);
            return int.Parse(Console.ReadLine());
        }
        catch (FormatException e)
        {
            Console.WriteLine(e.Message);
            return ReadNumber(msg);
        }
    }
    private static void ValidateOption(int option)
    {
        if (option > 3 || option < 1)
        {
            Console.WriteLine("You have entered invalid option!");
            Environment.Exit(1);
        }
    }
    static int AddNumbers(int firstNumber, int secondNumber)
    {
        return firstNumber + secondNumber;
    }
    static int SubstractNumbers(int firstNumber, int secondNumber)
    {
        return firstNumber - secondNumber;
    }
    static int MultiplyNumbers(int firstNumber, int secondNumber)
    {
        return firstNumber * secondNumber;
    }
}